<?php
namespace App\Models\Traits;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/7 0007
 * Time: 10:26
 */

trait NewUserHelper{

    public function getNewUser (){
        return Cache::remember('new_user',5,function (){
            return $this->calculateNewUser();
        });
    }
    public function calculateNewUser() {
        $active_users =  User::query()->where('email_verified_at','>=',Carbon::now()->subDay())->orderByDesc('created_at')->get();
        $register_users = User::query()->where('created_at','>=',Carbon::now()->subDay())->orderByDesc('created_at')->get();
        $datas = collect();
        $datas->put('active_users',$active_users);
        $datas->put('register_users',$register_users);
        return $datas;
    }
}
